﻿@using thousandClear.Areas.Admin.Models;
@model List<AddressModel>
@{
    ViewBag.Title = "地址管理";
    Layout = "~/Areas/Admin/Views/Shared/_Admin.cshtml";
}
<div id="divMain" style="width:100%; position:fixed; left:0px; top:0px; z-index:99999; background-color:white; filter:alpha(opacity=80);
	-moz-opacity:0.8;
	-khtml-opacity: 0.8;
	opacity: 0.8;">

    <img src="~/Statics/Images/Activity/load.gif" style="position:fixed; width:10%; left:40%; top:40%" />
</div>

<div id="app">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">后台管理</strong> / <small>@ViewBag.Title</small></div>
    </div>
    <div class="am-u-sm-12 am-u-md-2">
        <div class="am-form-group">
            <label>客户编号：</label>
            <input type="text" class="am-input-sm" id="nocusto" />
        </div>

    </div>
    <div class="am-u-sm-12 am-u-md-2">
        <div class="am-form-group">
            <label>姓名：</label>
            <input type="text" class="am-input-sm" id="namecusto" />
        </div>
    </div>

    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-12">
            <button class="am-btn am-btn-primary" onclick="searchop()">查询</button>
            @if (ViewBag.level != "2")
            {
                <button class="am-btn am-btn-primary" data-am-modal="{target: '#doc-modal-2', closeViaDimmer: 0, width: 800, height: 600}" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only">新增客户编号</button>
            }
        </div>
        <div class="am-g">
            <div class="am-u-sm-12">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                        <tr>

                            <th>客户编号</th>
                            <th>姓名</th>
                            <th>手机号</th>
                            <th>地址</th>
                            <th>详细地址</th>
                            <th>原始积分</th>
                            <th>是否绑定微信</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (AddressModel item in Model)
                        {
                            <tr>

                                <td>@item.oasNo</td>
                                <td>@item.oasName</td>
                                <td>@item.osaPhone</td>
                                <td>
                                    @item.DATIDdesc
                                </td>
                                <td>@item.oasAddressDetail</td>
                                <td>@item.oasPoint</td>
                                <td>@item.stutas</td>
                                <td>

                                <td>
                                    <div class="am-btn-toolbar" style="float:left; margin-left:5px;">
                                        <div class="am-btn-group am-btn-group-xs">
                                            @if (ViewBag.level != "2")
                                            {
                                                <a onclick="getinfo('@item.OASID-@item.osaPhone-@item.oasName-@item.oasPoint-@item.oasNo')" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0, width: 800, height: 600}" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span>修改信息/删除</a>
                                            }
                                        </div>
                                    </div>
                                </td>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div class="am-cf">
                    &nbsp;&nbsp;共 {{totalCount}} 条记录, 每页 {{pageCount}} 条记录
                    <div class="am-fr">
                        <ul class="am-pagination">
                            <li style="width: 60px">
                                <input class="am-form-field" style="text-align:center" type="text" v-model="gotoPage">

                            </li>
                            <li><a href="#" v-on:click="goto">GoTo &raquo;</a></li>
                            <li><a href="#" v-on:click="prev">&laquo; Prev</a></li>
                            <li><span>{{currentPage}}/{{totalPage}}</span></li>
                            <li><a href="#" v-on:click="next">Next &raquo;</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
    <div class="am-modal-dialog" style="overflow-y:auto;">
        <div class="am-modal-hd">
            修改客户信息
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <div class="am-g">
                <div class="am-u-sm-12">
                    <div class="am-form-group">
                        <label>ID：</label>
                        <span id="idosa" />
                    </div>
                    <div class="am-form-group">
                        <label>客户编号：</label>
                        <input type="text" id="cNos" class="am-input-sm" />
                    </div>
                    <div class="am-form-group">
                        <label>姓名：</label>
                        <input type="text" id="cNameS" class="am-input-sm" />
                    </div>
                    <div class="am-form-group">
                        <label>手机号：</label>
                        <input type="text" id="cPhoneS" class="am-input-sm" />
                    </div>
                    <div class="am-form-group">
                        <label>积分：</label>
                        <input type="text" class="am-input-sm" id="cPointS" />
                    </div>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-12">
                <button class="am-btn am-btn-primary" onclick="updateList()">修改客户信息</button>
                <button class="am-btn am-btn-primary" onclick="deleteAddress()">删除</button>
            </div>
        </div>
    </div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-2">
    <div class="am-modal-dialog" style="overflow-y:auto;">
        <div class="am-modal-hd">
            新增客户编号
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <div class="am-g">
                <div class="am-u-sm-12">
                    <div class="am-form-group">
                        <label>姓名：</label>
                        <input type="text" id="cName" class="am-input-sm" />
                    </div>
                    <div class="am-form-group">
                        <label>手机号：</label>
                        <input type="text" id="cPhone" class="am-input-sm" />
                    </div>
                    <div class="ui-form-item ui-border-b address">
                        <label>选择地区：</label>
                        <select id="ddlProvince">
                            <option v-bind:value="5">江苏省</option>
                        </select>
                        <select id="ddlCity">
                            <option v-bind:value="3">苏州市</option>
                        </select>
                        <select id="ddlBlock" v-model="cBlock">
                            <option value="1">工业园区</option>
                            <option value="12">吴中区</option>
                            <option value="13">姑苏区</option>
                            <option value="14">新区</option>
                            <option value="15">虎丘区</option>
                            <option value="16">古城区</option>
                            <option value="17">相城区</option>
                            <option value="18">金阊区</option>
                            <option value="19">平江区</option>
                            <option value="20">沧浪区</option>
                            <option value="21">常熟</option>
                            <option value="22">昆山</option>
                            <option value="23">张家港</option>
                            <option value="24">吴江</option>
                            <option value="25">太仓</option>
                        </select>
                    </div>

                    <div class="ui-form-item ui-border-b address">
                        <label>
                            详细地址
                        </label>
                        <input type="text" class="am-input-sm" id="cAddress" style="width:300px;" />
                    </div>
                    <div class="am-form-group">
                        <label>现有积分：</label>
                        <input type="text" class="am-input-sm" id="cPoint" />
                    </div>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-12">
                <button class="am-btn am-btn-primary" onclick="onSubOgr()">新增客户编号</button>
            </div>
        </div>
    </div>

</div>



@section Scripts{

    <script>
        var model = new Vue({
            el: '#app',
            data: {
                totalCount: @ViewBag.TotalCount,
                currentPage: @ViewBag.CurrentPage,
                pageCount: @ViewBag.PageCount,
                gotoPage: @ViewBag.CurrentPage,
                totalPage: @ViewBag.TotalPage,
                phone:'@ViewBag.phone',
                cName:'',
                cPhone:'',
                cBlock:0,
                cAddress:'',
                cPoint:''
            },
            computed: {
                data: function () {

                    return JSON.stringify(this._data);
                }
            },
            methods: {
                prev: function() {
                    var self = this;
                    if (self.currentPage <= 1)
                        return;

                    self.currentPage -= 1;
                    self.load();
                },
                next: function() {
                    var self = this;

                    if (self.currentPage >= self.totalPage)
                        return;

                    self.currentPage += 1;

                    self.load();
                },
                goto: function() {
                    var self = this;
                    self.currentPage = self.gotoPage;
                    self.load();
                },
                search: function() {
                    var self = this;
                    self.currentPage = 1;
                    self.load();
                },
                load: function() {
                    var self = this;
                    window.location.href = "../admin/Address?page=" + self.currentPage + "&count=" + self.pageCount;
                }
            }
        });


        $('.admin-sidebar-Address').addClass('current');

        function onSubOgr(){
            showLoading();
            var data1 = '{"cName":"'+$("#cName").val()+'","cPhone":"'+$("#cPhone").val()+'","ddlBlock":"'+$("#ddlBlock").val()+'","cAddress":"'+$("#cAddress").val()+'","cPoint":"'+$("#cPoint").val()+'"}';
            $.ajax({
                type: "POST",
                url: "../admin/Address/CreateAddress",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {
                    var ss = responseData;
                    closeLoading();
                    if(ss=="1"){
                        window.location.href="../admin/Address";
                    }
                }
            });
        }

        $(function() {

            $("#divMain").css("height",$(window).height()+"px");
            closeLoading();
        });

        function showLoading(){

            $("#divMain").css("display","");
        }

        function closeLoading(){

            $("#divMain").css("display","none");
        }


        function searchop(){

            window.location.href = "../admin/Address?no="+ $("#nocusto").val()+"&name="+$("#namecusto").val();
        }

        function getinfo(obj){

            $("#idosa").text(obj.toString().split('-')[0])
            $("#cNameS").val(obj.toString().split('-')[2])
            $("#cPhoneS").val(obj.toString().split('-')[1])
            $("#cPointS").val(obj.toString().split('-')[3])
            $("#cNos").val(obj.toString().split('-')[4])

        }

        function updateList(){

            var data1 = '{"oasid":"'+$("#idosa").text()+'","phone":"'+$("#cPhoneS").val()+'","point":"'+$("#cPointS").val()+'","name":"'+$("#cNameS").val()+'","casn":"'+$("#cNos").val()+'"}';

            showLoading();
            $.ajax({
                type: "POST",
                url: "../admin/Address/updateList",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {

                    closeLoading();

                    if(responseData.toString()=="-1"){
                        alert("修改的客户编号已存在，请先确认再更改");
                    }
                    else{
                        window.location.reload();
                    }



                }
            });
        }

        function deleteAddress(){

            showLoading();
            var data1 = '{"oasid":"'+$("#idosa").text()+'"}';
            $.ajax({
                type: "POST",
                url: "../admin/Address/RemovAddress",
                contentType: "application/json",
                data: data1,
                success: function (responseData) {
                    window.location.reload();
                }
            });

        }

    </script>


}

